﻿//**************************************************
//CLASS : tcdc_mst_dashboard
//AUTHOR : PATTARAWUT CHANNGAM & SUCHIN INPIRUT
//LAST MODIFIED : Monday, February 25, 2013
//**************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Model
{

public class tcdc_mst_dashboard
{

     private DBUtil DB;
     public string strConn { get; set; }
     public int dashboard_id {get;set;}
     public string description {get;set;}
     public int parent_id {get;set;}
     public int sorting_no {get;set;}
     public int function_id {get;set;}
     public string icon {get;set;}
     public string Link {get;set;}

     public tcdc_mst_dashboard() {
          this.DB = new DBUtil();
          DB.strConn = strConn;
     }

     public DataTable getById(string id) {

          DataTable dt = new DataTable();
          this.DB = new DBUtil();
          DB.strConn = strConn;

          string sql = "SELECT * FROM tcdc_mst_dashboard" + 
                       " WHERE dashboard_id = '" + id + "'";

          dt = DB.ExecuteReader(sql);

          return dt;

     }

     public DataTable getByObject(tcdc_mst_dashboard obj) {

          DataTable dt = new DataTable();
          this.DB = new DBUtil();
          DB.strConn = strConn;

          string sql = "SELECT * FROM tcdc_mst_dashboard " + 
                       "WHERE 1 = 1 ";

          if(obj.dashboard_id != null && 
             obj.dashboard_id.ToString() != null && 
             obj.dashboard_id.ToString() != "0")
          {
               sql += "AND dashboard_id LIKE '%" + obj.dashboard_id + "%' ";
          }
          if(obj.description != null && 
             obj.description.ToString() != null && 
             obj.description.ToString() != "0")
          {
               sql += "AND description LIKE '%" + obj.description + "%' ";
          }
          if(obj.parent_id != null && 
             obj.parent_id.ToString() != null && 
             obj.parent_id.ToString() != "0")
          {
               sql += "AND parent_id LIKE '%" + obj.parent_id + "%' ";
          }
          if(obj.sorting_no != null && 
             obj.sorting_no.ToString() != null && 
             obj.sorting_no.ToString() != "0")
          {
               sql += "AND sorting_no LIKE '%" + obj.sorting_no + "%' ";
          }
          if(obj.function_id != null && 
             obj.function_id.ToString() != null && 
             obj.function_id.ToString() != "0")
          {
               sql += "AND function_id LIKE '%" + obj.function_id + "%' ";
          }
          if(obj.icon != null && 
             obj.icon.ToString() != null && 
             obj.icon.ToString() != "0")
          {
               sql += "AND icon LIKE '%" + obj.icon + "%' ";
          }
          if(obj.Link != null && 
             obj.Link.ToString() != null && 
             obj.Link.ToString() != "0")
          {
               sql += "AND Link LIKE '%" + obj.Link + "%' ";
          }
          dt = DB.ExecuteReader(sql);

          return dt;

     }

     public int insertData(tcdc_mst_dashboard obj) {

          this.DB = new DBUtil();
          DB.strConn = strConn;

          SqlParameter[] prm;
          prm = new SqlParameter[7];

          prm[0] = new SqlParameter("@description", SqlDbType.NVarChar,250);
          if(obj.description != null && 
             obj.description.ToString() != null && 
             obj.description.ToString() != "0")
          {
               prm[0].Value = obj.description;
          }
          else
          {
               prm[0].Value = DBNull.Value;
          }

          prm[1] = new SqlParameter("@parent_id", SqlDbType.Int);
          if(obj.parent_id != null && 
             obj.parent_id.ToString() != null && 
             obj.parent_id.ToString() != "0")
          {
               prm[1].Value = obj.parent_id;
          }
          else
          {
               prm[1].Value = DBNull.Value;
          }

          prm[2] = new SqlParameter("@sorting_no", SqlDbType.Int);
          if(obj.sorting_no != null && 
             obj.sorting_no.ToString() != null && 
             obj.sorting_no.ToString() != "0")
          {
               prm[2].Value = obj.sorting_no;
          }
          else
          {
               prm[2].Value = DBNull.Value;
          }

          prm[3] = new SqlParameter("@function_id", SqlDbType.Int);
          if(obj.function_id != null && 
             obj.function_id.ToString() != null && 
             obj.function_id.ToString() != "0")
          {
               prm[3].Value = obj.function_id;
          }
          else
          {
               prm[3].Value = DBNull.Value;
          }

          prm[4] = new SqlParameter("@icon", SqlDbType.NVarChar,250);
          if(obj.icon != null && 
             obj.icon.ToString() != null && 
             obj.icon.ToString() != "0")
          {
               prm[4].Value = obj.icon;
          }
          else
          {
               prm[4].Value = DBNull.Value;
          }

          prm[5] = new SqlParameter("@Link", SqlDbType.NVarChar,250);
          if(obj.Link != null && 
             obj.Link.ToString() != null && 
             obj.Link.ToString() != "0")
          {
               prm[5].Value = obj.Link;
          }
          else
          {
               prm[5].Value = DBNull.Value;
          }

          prm[6] = new SqlParameter("@ReturnValue", SqlDbType.Int);
          prm[6].Direction = ParameterDirection.Output;

          DB.ExecuteNonQueryProc("sp_tcdc_mst_dashboard_insert", prm, false);
          return (Int32)prm[6].Value;
     }

     public int updateData(tcdc_mst_dashboard obj) {

          this.DB = new DBUtil();
          DB.strConn = strConn;

          SqlParameter[] prm;
          prm = new SqlParameter[7];

          prm[0] = new SqlParameter("@dashboard_id", SqlDbType.Int);
          if(obj.dashboard_id != null && 
             obj.dashboard_id.ToString() != null && 
             obj.dashboard_id.ToString() != "0")
          {
               prm[0].Value = obj.dashboard_id;
          }
          else
          {
               prm[0].Value = DBNull.Value;
          }
          prm[1] = new SqlParameter("@description", SqlDbType.NVarChar,250);
          if(obj.description != null && 
             obj.description.ToString() != null && 
             obj.description.ToString() != "0")
          {
               prm[1].Value = obj.description;
          }
          else
          {
               prm[1].Value = DBNull.Value;
          }
          prm[2] = new SqlParameter("@parent_id", SqlDbType.Int);
          if(obj.parent_id != null && 
             obj.parent_id.ToString() != null && 
             obj.parent_id.ToString() != "0")
          {
               prm[2].Value = obj.parent_id;
          }
          else
          {
               prm[2].Value = DBNull.Value;
          }
          prm[3] = new SqlParameter("@sorting_no", SqlDbType.Int);
          if(obj.sorting_no != null && 
             obj.sorting_no.ToString() != null && 
             obj.sorting_no.ToString() != "0")
          {
               prm[3].Value = obj.sorting_no;
          }
          else
          {
               prm[3].Value = DBNull.Value;
          }
          prm[4] = new SqlParameter("@function_id", SqlDbType.Int);
          if(obj.function_id != null && 
             obj.function_id.ToString() != null && 
             obj.function_id.ToString() != "0")
          {
               prm[4].Value = obj.function_id;
          }
          else
          {
               prm[4].Value = DBNull.Value;
          }
          prm[5] = new SqlParameter("@icon", SqlDbType.NVarChar,250);
          if(obj.icon != null && 
             obj.icon.ToString() != null && 
             obj.icon.ToString() != "0")
          {
               prm[5].Value = obj.icon;
          }
          else
          {
               prm[5].Value = DBNull.Value;
          }
          prm[6] = new SqlParameter("@Link", SqlDbType.NVarChar,250);
          if(obj.Link != null && 
             obj.Link.ToString() != null && 
             obj.Link.ToString() != "0")
          {
               prm[6].Value = obj.Link;
          }
          else
          {
               prm[6].Value = DBNull.Value;
          }

          return DB.ExecuteNonQueryProc("sp_tcdc_mst_dashboard_update", prm, false);
     }

     public int deleteData(string id) {

          this.DB = new DBUtil();
          DB.strConn = strConn;

          SqlParameter[] prm;
          prm = new SqlParameter[1];

          prm[0] = new SqlParameter("@dashboard_id", id);

          return DB.ExecuteNonQueryProc("sp_tcdc_mst_dashboard_delete", prm, false);
     }
}

}

